<template>
  <div class="">
    <van-search
      v-model="value"
      show-action
      label="图书"
      placeholder="请输入搜索关键词"
      @search="onSearch"
    >
      <template #action>
        <div @click="onSearch">搜索</div>
      </template>
    </van-search>

    <van-button @click="clear">清空</van-button>
    <ul>
      <li v-for="(item, index) in $store.state.history" :key="index">
        {{ item }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
    };
  },
  created() {},
  methods: {
    onSearch() {
      this.$store.commit("add", this.value);
      this.$router.push({ path: "/", query: { keyword: this.value } });
    },
    clear() {
      this.$store.commit("clear");
    },
  },
  components: {},
};
</script>

<style lang="scss"></style>
